
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:yp/helper.dart';
import 'package:yp/router.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';

import 'logic.dart';
import 'state.dart';

class IssueInvoicePage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return _IssueInvoicePage();
  }
}

class _IssueInvoicePage extends State<IssueInvoicePage> {
  final IssueInvoiceLogic logic = Get.put(IssueInvoiceLogic());
  final IssueInvoiceState state = Get.find<IssueInvoiceLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: setWidth(1),
        centerTitle: true,
        title: Text(
          '开具发票',
          style: TextStyle(
            color: Colors.black,
            fontSize: 18,
            fontWeight: FontWeight.bold,
          ),
        ),
        iconTheme: IconThemeData(
          color: Colors.black,
        ),
      ),
      body: GetBuilder<IssueInvoiceLogic>(
        builder: (logic) {
          return Container(
            color: Color(0xffF5F5F5),
            child: Column(
              children: [
                Expanded(
                  child: Container(
                    child: ListView(
                      padding: EdgeInsets.only(bottom: setWidth(26)),
                      children: [
                        _contentWidget(),
                      ],
                    ),
                  ),
                ),
                InkWell(
                  onTap: () {
                    print('保存按钮点击事件！！！');
                    logic.preservationIssueInvoice();
                  },
                  child: Container(
                    color: Color(0xffEA5504),
                    height: setWidth(96),
                    alignment: Alignment.center,
                    child: Text(
                      '保存',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 17,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          );
        },
      ),
    );
  }

  Widget _contentWidget() {
    return Container(
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 开具发票
          Container(
            height: setWidth(212),
            padding: EdgeInsets.only(
              left: setWidth(32),
              top: setWidth(38),
              right: setWidth(22),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Text(
                      '开具发票',
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 17,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    Expanded(
                      child: Padding(
                        padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                        child: Row(
                          children: [
                            Text(
                              '发票须知',
                              style: TextStyle(
                                color: Color(0xff999999),
                                fontSize: 14,
                              ),
                            ),
                            InkWell(
                              onTap: () {
                                print('！！！发票须知 点击事件 ！！！');
                              },
                              child: Container(
                                padding: EdgeInsets.symmetric(horizontal: setWidth(10), vertical: setWidth(6),),
                                child: Icon(
                                  Icons.error,
                                  color: Color(0xffcccccc),
                                  size: setWidth(24),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    InkWell(
                      onTap: () {
                        print('======== 导入微信发票 点击事件 ========');
                        showDialog(
                          context: context,
                          useSafeArea: false,
                          builder: (BuildContext context) {
                            return Container(
                              color: Color(0x66030303),
                              child: CupertinoAlertDialog(
                                title: Text(
                                  "“激荡优选”要获取您的发票抬头， 是否允许？",
                                ),
                                actions: <Widget>[
                                  CupertinoDialogAction(
                                    child: Text("取消"),
                                    onPressed: () {
                                      Get.back();
                                      print("取消");
                                    },
                                  ),
                                  CupertinoDialogAction(
                                    child: Text("确定"),
                                    onPressed: () {
                                      Get.back();
                                      Get.toNamed(RouteConfig.selectInvoiceHead);
                                      print("确定");
                                    },
                                  ),
                                ],
                              ),
                            );
                          },
                        );
                      },
                      child: Text(
                        '导入微信发票',
                        style: TextStyle(
                          color: Color(0xffEA5504),
                          fontSize: 14,
                        ),
                      ),
                    ),
                  ],
                ),
                SizedBox(height: setWidth(42)),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    InkWell(
                      onTap: () {
                        print('！！！纸质发票选择事件！！！');
                        if (!state.paperInvoiceBool) {
                          state.paperInvoiceBool = !state.paperInvoiceBool;
                          setState(() {});
                        }
                      },
                      child: Row(
                        children: [
                          Icon(
                            state.paperInvoiceBool ? Icons.check_circle : Icons.panorama_fisheye,
                            color: state.paperInvoiceBool ? Color(0xffEA5504) : Color(0xffcccccc),
                            size: setWidth(40),
                          ),
                          SizedBox(
                            width: setWidth(20),
                          ),
                          Text(
                            '纸质发票',
                            style: TextStyle(
                              color: Color(0xff262626),
                              fontSize: 14,
                            ),
                          ),
                        ],
                      ),
                    ),
                    SizedBox(width: setWidth(96)),
                    InkWell(
                      onTap: () {
                        print('！！！不需要发票选择事件！！！');
                        if (state.paperInvoiceBool) {
                          state.paperInvoiceBool = !state.paperInvoiceBool;
                          setState(() {});
                        }
                      },
                      child: Row(
                        children: [
                          Icon(
                            state.paperInvoiceBool ? Icons.panorama_fisheye : Icons.check_circle,
                            color: state.paperInvoiceBool ? Color(0xffcccccc) : Color(0xffEA5504),
                            size: setWidth(40),
                          ),
                          SizedBox(
                            width: setWidth(20),
                          ),
                          Text(
                            '不需要发票',
                            style: TextStyle(
                              color: Color(0xff262626),
                              fontSize: 14,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          Divider(
            height: setWidth(1),
            indent: setWidth(32),
            endIndent: 0,
            color: Color(0xffEFEFEF),
          ),
          // 发票抬头
          Container(
            padding: EdgeInsets.only(
              top: setWidth(20),
              bottom: setWidth(22),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  padding: EdgeInsets.only(
                    left: setWidth(32),
                    right: setWidth(22),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '发票抬头',
                        style: TextStyle(
                          color: Colors.black,
                          fontSize: 17,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      SizedBox(height: setWidth(30)),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          InkWell(
                            onTap: () {
                              print('！！！纸质发票选择事件！！！');
                              if (!state.invoiceHeaderBool) {
                                state.invoiceHeaderBool = !state.invoiceHeaderBool;
                                state.invoiceHeaderMap = null;
                                setState(() {});
                              }
                            },
                            child: Row(
                              children: [
                                Icon(
                                  state.invoiceHeaderBool ? Icons.check_circle : Icons.panorama_fisheye,
                                  color: state.invoiceHeaderBool ? Color(0xffEA5504) : Color(0xffcccccc),
                                  size: setWidth(40),
                                ),
                                SizedBox(
                                  width: setWidth(20),
                                ),
                                Text(
                                  '个人/非企业',
                                  style: TextStyle(
                                    color: Color(0xff2B2B2B),
                                    fontSize: 14,
                                  ),
                                ),
                              ],
                            ),
                          ),
                          SizedBox(width: setWidth(56)),
                          InkWell(
                            onTap: () {
                              print('！！！不需要发票选择事件！！！');
                              if (state.invoiceHeaderBool) {
                                state.invoiceHeaderBool = !state.invoiceHeaderBool;
                                state.invoiceHeaderMap = null;
                                setState(() {});
                              }
                            },
                            child: Row(
                              children: [
                                Icon(
                                  state.invoiceHeaderBool ? Icons.panorama_fisheye : Icons.check_circle,
                                  color: state.invoiceHeaderBool ? Color(0xffcccccc) : Color(0xffEA5504),
                                  size: setWidth(40),
                                ),
                                SizedBox(
                                  width: setWidth(20),
                                ),
                                Text(
                                  '企业',
                                  style: TextStyle(
                                    color: Color(0xff303030),
                                    fontSize: 14,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
                state.invoiceHeaderBool ? Container(
                  padding: EdgeInsets.only(
                    left: setWidth(32),
                    right: setWidth(22),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: setWidth(44)),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(
                            '发票名称',
                            style: TextStyle(
                              color: Color(0xff717171),
                              fontSize: 13,
                            ),
                          ),
                          Expanded(
                            child: Padding(
                              padding: EdgeInsets.symmetric(horizontal: setWidth(40)),
                              child: Text(
                                state.invoiceHeaderMap == null ? '请选择信息' : state.invoiceHeaderMap['invoice_title'],
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: state.invoiceHeaderMap == null ? Color(0xffaaaaaa) : Color(0xff2b2b2b),
                                  fontSize: 13,
                                ),
                              ),
                            ),
                          ),
                          InkWell(
                            onTap: () {
                              print('选择发票事件！！！');
                              Get.toNamed(RouteConfig.invoiceHeaderManagement, arguments: {'chooseType': true}).then((value) {
                                print('发票抬头 选择事件 返回！！！ value = $value');
                                if (value != null) {
                                  state.invoiceHeaderMap = value;
                                  setState(() { });
                                }
                                state.invoiceNameController.text = '';
                                state.dutyParagraphController.text = '';
                                state.businessAddressController.text = '';
                                state.enterpriseTelephoneController.text = '';
                                state.bankOfDepositController.text = '';
                                state.bankAccountController.text = '';
                              });
                            },
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Text(
                                  '请选择',
                                  style: TextStyle(
                                    color: Color(0xffea5504),
                                    fontSize: 13,
                                  ),
                                ),
                                SizedBox(width: setWidth(16)),
                                Column(
                                  children: [
                                    SizedBox(height: setWidth(2)),
                                    Image.asset(
                                      'assets/images/arrow_right.png',
                                      width: setWidth(14),
                                      height: setWidth(30),
                                      fit: BoxFit.cover,
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ) : Container(
                  padding: EdgeInsets.only(
                    top: setWidth(10),
                    left: setWidth(32),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          // 发票名称
                          Row(
                            children: [
                              Container(
                                height: setWidth(86),
                                width: setWidth(150),
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  '发票名称',
                                  style: TextStyle(
                                    color: Color(0xff666666),
                                    fontSize: 13,
                                  ),
                                ),
                              ),
                              Expanded(
                                child: Container(
                                  height: setWidth(86),
                                  child: TextField(
                                    controller: state.invoiceNameController,
                                    maxLines: 1,
                                    style: TextStyle(
                                      color: Color(0xff222222),
                                      fontSize: 13,
                                    ),
                                    // onChanged: (text) {
                                    //   logic.whetherAvailableClick();
                                    // },
                                    enabled: false,
                                    decoration: InputDecoration(
                                      contentPadding: EdgeInsets.zero,
                                      hintText: '请输入发票名称',
                                      hintStyle: TextStyle(
                                        color: Color(0xff999999),
                                        fontSize: 13,
                                      ),
                                      enabledBorder: OutlineInputBorder( // 设置输入框可编辑时的边框样式
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                      focusedBorder: OutlineInputBorder(  // 用来配置输入框获取焦点时的颜色
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                      disabledBorder: OutlineInputBorder( // 设置输入框可编辑时的边框样式
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                              InkWell(
                                onTap: () {
                                  print('选择 发票名称 点击事件！！！');
                                  // showDialog(
                                  //   context: context,
                                  //   useSafeArea: false,
                                  //   builder: (context) {
                                  //     return SelectInvoiceHeaderWidget(chooseIndex: state.invoiceHeaderIndex, indexType: 2,);
                                  //   },
                                  // );
                                  Get.toNamed(RouteConfig.invoiceHeaderManagement, arguments: {'chooseType': true}).then((value) {
                                    print('发票抬头 选择事件 返回！！！ value = $value');
                                    if (value != null) {
                                      state.invoiceHeaderMap = value;
                                      state.invoiceNameController.text = value['invoice_title'];
                                      state.dutyParagraphController.text = value['consumer_tax_account'];
                                      state.businessAddressController.text = value['consumer_addr'];
                                      state.enterpriseTelephoneController.text = value['consumer_telephone'];
                                      state.bankOfDepositController.text = value['consumer_bank_name'];
                                      state.bankAccountController.text = value['consumer_bank_account'];
                                      setState(() { });
                                    }
                                  });
                                },
                                child: Container(
                                  height: setWidth(86),
                                  width: setWidth(130),
                                  alignment: Alignment.centerRight,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.end,
                                    children: [
                                      Text(
                                        '请选择',
                                        style: TextStyle(
                                          color: Color(0xffea5504),
                                          fontSize: 13,
                                        ),
                                      ),
                                      SizedBox(width: setWidth(16)),
                                      Image.asset(
                                        'assets/images/arrow_right.png',
                                        width: setWidth(12),
                                        height: setWidth(30),
                                        fit: BoxFit.cover,
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                              SizedBox(width: setWidth(22)),
                            ],
                          ),
                          Divider(
                            height: setWidth(1),
                            indent: 0,
                            endIndent: 0,
                            color: Color(0xffEFEFEF),
                          ),
                          // 税号
                          Row(
                            children: [
                              Container(
                                height: setWidth(86),
                                width: setWidth(150),
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  '税号',
                                  style: TextStyle(
                                    color: Color(0xff666666),
                                    fontSize: 13,
                                  ),
                                ),
                              ),
                              Expanded(
                                child: Container(
                                  height: setWidth(86),
                                  child: TextField(
                                    controller: state.dutyParagraphController,
                                    maxLines: 1,
                                    style: TextStyle(
                                      color: Color(0xff222222),
                                      fontSize: 13,
                                    ),
                                    decoration: InputDecoration(
                                      contentPadding: EdgeInsets.zero,
                                      hintText: '请输入纳税人识别号',
                                      hintStyle: TextStyle(
                                        color: Color(0xff999999),
                                        fontSize: 13,
                                      ),
                                      enabledBorder: OutlineInputBorder( // 设置输入框可编辑时的边框样式
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                      focusedBorder: OutlineInputBorder(  // 用来配置输入框获取焦点时的颜色
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                              SizedBox(width: setWidth(22)),
                            ],
                          ),
                          Divider(
                            height: setWidth(1),
                            indent: 0,
                            endIndent: 0,
                            color: Color(0xffEFEFEF),
                          ),
                          // 企业地址
                          Padding(
                            padding: EdgeInsets.symmetric(vertical: setWidth(24)),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Container(
                                  width: setWidth(150),
                                  alignment: Alignment.centerLeft,
                                  child: Text(
                                    '企业地址',
                                    style: TextStyle(
                                      color: Color(0xff666666),
                                      fontSize: 13,
                                    ),
                                  ),
                                ),
                                Expanded(
                                  child: Container(
                                    child: TextField(
                                      controller: state.businessAddressController,
                                      maxLines: 3,
                                      style: TextStyle(
                                        color: Color(0xff222222),
                                        fontSize: 13,
                                      ),
                                      decoration: InputDecoration(
                                        contentPadding: EdgeInsets.zero,
                                        hintText: '请输入企业注册地址',
                                        hintStyle: TextStyle(
                                          color: Color(0xff999999),
                                          fontSize: 13,
                                        ),
                                        enabledBorder: OutlineInputBorder( // 设置输入框可编辑时的边框样式
                                          borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                          borderSide: BorderSide(  // 用来配置边框的样式
                                            color: Colors.transparent,  // 设置边框的颜色
                                            width: setWidth(1),  // 设置边框的粗细
                                          ),
                                        ),
                                        focusedBorder: OutlineInputBorder(  // 用来配置输入框获取焦点时的颜色
                                          borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                          borderSide: BorderSide(  // 用来配置边框的样式
                                            color: Colors.transparent,  // 设置边框的颜色
                                            width: setWidth(1),  // 设置边框的粗细
                                          ),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                                SizedBox(width: setWidth(22)),
                              ],
                            ),
                          ),
                          Divider(
                            height: setWidth(1),
                            indent: 0,
                            endIndent: 0,
                            color: Color(0xffEFEFEF),
                          ),
                          // 企业电话
                          Row(
                            children: [
                              Container(
                                height: setWidth(86),
                                width: setWidth(150),
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  '企业电话',
                                  style: TextStyle(
                                    color: Color(0xff666666),
                                    fontSize: 13,
                                  ),
                                ),
                              ),
                              Expanded(
                                child: Container(
                                  height: setWidth(86),
                                  child: TextField(
                                    controller: state.enterpriseTelephoneController,
                                    maxLines: 1,
                                    style: TextStyle(
                                      color: Color(0xff222222),
                                      fontSize: 13,
                                    ),
                                    keyboardType: TextInputType.phone,
                                    decoration: InputDecoration(
                                      contentPadding: EdgeInsets.zero,
                                      hintText: '请输入企业注册电话',
                                      hintStyle: TextStyle(
                                        color: Color(0xff999999),
                                        fontSize: 13,
                                      ),
                                      enabledBorder: OutlineInputBorder( // 设置输入框可编辑时的边框样式
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                      focusedBorder: OutlineInputBorder(  // 用来配置输入框获取焦点时的颜色
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                              SizedBox(width: setWidth(22)),
                            ],
                          ),
                          Divider(
                            height: setWidth(1),
                            indent: 0,
                            endIndent: 0,
                            color: Color(0xffEFEFEF),
                          ),
                          // 开户银行
                          Row(
                            children: [
                              Container(
                                height: setWidth(86),
                                width: setWidth(150),
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  '开户银行',
                                  style: TextStyle(
                                    color: Color(0xff666666),
                                    fontSize: 13,
                                  ),
                                ),
                              ),
                              Expanded(
                                child: Container(
                                  height: setWidth(86),
                                  child: TextField(
                                    controller: state.bankOfDepositController,
                                    maxLines: 1,
                                    style: TextStyle(
                                      color: Color(0xff222222),
                                      fontSize: 13,
                                    ),
                                    decoration: InputDecoration(
                                      contentPadding: EdgeInsets.zero,
                                      hintText: '请输入企业开户银行',
                                      hintStyle: TextStyle(
                                        color: Color(0xff999999),
                                        fontSize: 13,
                                      ),
                                      enabledBorder: OutlineInputBorder( // 设置输入框可编辑时的边框样式
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                      focusedBorder: OutlineInputBorder(  // 用来配置输入框获取焦点时的颜色
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                              SizedBox(width: setWidth(22)),
                            ],
                          ),
                          Divider(
                            height: setWidth(1),
                            indent: 0,
                            endIndent: 0,
                            color: Color(0xffEFEFEF),
                          ),
                          // 银行账号
                          Row(
                            children: [
                              Container(
                                height: setWidth(86),
                                width: setWidth(150),
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  '银行账号',
                                  style: TextStyle(
                                    color: Color(0xff666666),
                                    fontSize: 13,
                                  ),
                                ),
                              ),
                              Expanded(
                                child: Container(
                                  height: setWidth(86),
                                  child: TextField(
                                    controller: state.bankAccountController,
                                    maxLines: 1,
                                    style: TextStyle(
                                      color: Color(0xff222222),
                                      fontSize: 13,
                                    ),
                                    keyboardType: TextInputType.number,
                                    decoration: InputDecoration(
                                      contentPadding: EdgeInsets.zero,
                                      hintText: '请输入企业银行账号',
                                      hintStyle: TextStyle(
                                        color: Color(0xff999999),
                                        fontSize: 13,
                                      ),
                                      enabledBorder: OutlineInputBorder( // 设置输入框可编辑时的边框样式
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                      focusedBorder: OutlineInputBorder(  // 用来配置输入框获取焦点时的颜色
                                        borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                        borderSide: BorderSide(  // 用来配置边框的样式
                                          color: Colors.transparent,  // 设置边框的颜色
                                          width: setWidth(1),  // 设置边框的粗细
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                              SizedBox(width: setWidth(22)),
                            ],
                          ),
                          Divider(
                            height: setWidth(1),
                            indent: 0,
                            endIndent: 0,
                            color: Color(0xffEFEFEF),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: setWidth(1),
            indent: setWidth(32),
            endIndent: 0,
            color: Color(0xffEFEFEF),
          ),
          // 收票人信息
          Container(
            padding: EdgeInsets.only(
              left: setWidth(32),
              top: setWidth(32),
              right: setWidth(22),
              bottom: setWidth(32),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '收票人信息',
                  style: TextStyle(
                    color: Color(0xff020202),
                    fontSize: 17,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(height: setWidth(20)),
                state.chooseIndex < 0 ? InkWell(
                  onTap: () {
                    print('添加收票信息 点击事件！！！');
                    showDialog(
                      context: context,
                      useSafeArea: false,
                      builder: (context) {
                        return InvoiceWidget(
                          chooseNum: state.chooseIndex,
                          addressList: state.addressList,
                        );
                      },
                    );
                  },
                  child: Container(
                    height: setWidth(40),
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Image.asset(
                          'assets/images/plusSign_image.png',
                          width: setWidth(24),
                          height: setWidth(24),
                          fit: BoxFit.cover,
                        ),
                        SizedBox(width: setWidth(10)),
                        Text(
                          '添加收票信息',
                          style: TextStyle(
                            color: Color(0xffEA5504),
                            fontSize: 14,
                          ),
                        ),
                      ],
                    ),
                  ),
                ) : Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '${state.addressList[state.chooseIndex]['cont_empe']}  ${state.addressList[state.chooseIndex]['contact_no']}',  // '王麻子 13816545241',
                          style: TextStyle(
                            color: Color(0xff3F3F3F),
                            fontSize: 15,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        InkWell(
                          onTap: () {
                            print('更换地址 点击事件！！！');
                            showDialog(
                              context: context,
                              useSafeArea: false,
                              builder: (context) {
                                return InvoiceWidget(
                                  chooseNum: state.chooseIndex,
                                  addressList: state.addressList,
                                );
                              },
                            );
                          },
                          child: Row(
                            children: [
                              Text(
                                '更换地址',
                                style: TextStyle(
                                  color: Color(0xffEA5504),
                                  fontSize: 13,
                                ),
                              ),
                              SizedBox(width: setWidth(16)),
                              Column(
                                children: [
                                  SizedBox(height: setWidth(4)),
                                  Image.asset(
                                    'assets/images/arrow_right.png',
                                    width: setWidth(14),
                                    height: setWidth(30),
                                    fit: BoxFit.cover,
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    SizedBox(height: setWidth(20)),
                    Text(
                      '${state.addressList[state.chooseIndex]['prv_name']} ${state.addressList[state.chooseIndex]['city_name']} ${state.addressList[state.chooseIndex]['city_area_name']} ${state.addressList[state.chooseIndex]['adr']}',  //'江苏省 苏州市 昆山市 花桥镇 绿地大道211号 启航城晶彩小区 36号402室',
                      style: TextStyle(
                        color: Color(0xff7D7D7D),
                        fontSize: 13,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          Divider(
            height: setWidth(1),
            indent: setWidth(32),
            endIndent: 0,
            color: Color(0xffEFEFEF),
          ),
          // 发票内容
          Container(
            padding: EdgeInsets.only(
              left: setWidth(32),
              top: setWidth(32),
              right: setWidth(28),
              bottom: setWidth(40),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '发票内容',
                  style: TextStyle(
                    color: Color(0xff020202),
                    fontSize: 17,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(height: setWidth(30)),
                InkWell(
                  onTap: () {
                    print('！！！商品明细 点击事件！！！');
                  },
                  child: Container(
                    height: setWidth(40),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Icon(
                          Icons.check_circle,
                          color: Color(0xffEA5504),
                          size: setWidth(40),
                        ),
                        SizedBox(
                          width: setWidth(20),
                        ),
                        Text(
                          '商品明细',
                          style: TextStyle(
                            color: Color(0xff303030),
                            fontSize: 14,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                SizedBox(height: setWidth(22)),
                Text(
                  '商品明细：发票内容将显示商品名称与价格信息，发票金额为实际支付金额，不含虚拟资产、优惠券等扣减金额。',
                  style: TextStyle(
                    color: Color(0xffC5C6C5),
                    fontSize: 12,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

}
// 收票信息
class InvoiceWidget extends StatefulWidget {
  final int chooseNum;
  final List addressList;
  InvoiceWidget({this.chooseNum, this.addressList});
  @override
  State<StatefulWidget> createState() {
    return _InvoiceWidget(chooseIndex: chooseNum, addressList: addressList);
  }
}

class _InvoiceWidget extends State<InvoiceWidget> {
  final IssueInvoiceLogic logic = Get.put(IssueInvoiceLogic());
  int chooseIndex;
  List addressList;
  _InvoiceWidget({this.chooseIndex, this.addressList});

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height / 2,
          color: Colors.white,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: EdgeInsets.only(
                  left: setWidth(20),
                  top: setWidth(12),
                  right: setWidth(20),
                  bottom: setWidth(10),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Column(
                      children: [
                        SizedBox(height: setWidth(6)),
                        Text(
                          '收票信息',
                          style: TextStyle(
                            color: Color(0xff020202),
                            fontSize: 17,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ],
                    ),
                    InkWell(
                      onTap: () {
                        print('++++++++++++++ 隐藏点击事件 ++++++++++++++');
                        Get.back();
                      },
                      child: Padding(
                        padding: EdgeInsets.all(setWidth(10)),
                        child: Image.asset(
                          'assets/images/close2.png',
                          width: setWidth(50),
                          height: setWidth(50),
                          fit: BoxFit.cover,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Container(
                  child: ListView.separated(
                    scrollDirection: Axis.vertical,
                    padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                    itemBuilder: (context, index) {
                      if (index == addressList.length) {
                        return InkWell(
                          onTap: () {
                            print('新增收票信息 点击事件！！！！');
                            Get.back();
                            Get.toNamed(RouteConfig.addressCreate, arguments: {"userNum": SpUtil.getInt('empeNumId')}).then((value) {
                              if (value != '' && value != null) {
                                //刷新列表页
                                logic.onReady();
                              }
                            });
                          },
                          child: Container(
                            height: setWidth(120),
                            alignment: Alignment.center,
                            child: Text(
                              '+新增收票信息',
                              style: TextStyle(
                                color: Color(0xffea5504),
                                fontSize: 16,
                              ),
                            ),
                          ),
                        );
                      }
                      Map<String, dynamic> map = addressList[index];
                      return InkWell(
                        onTap: () {
                          if (chooseIndex != index) {
                            print('++++++++++ 收票信息 选择事件 ++++++++++');
                            setState(() {
                              chooseIndex = index;
                            });
                          }
                        },
                        child: Container(
                          height: setWidth(176),
                          decoration: BoxDecoration(
                            color: Colors.white,
                            border: Border.all(
                              color: chooseIndex == index ? Color(0xffea5504) : Color(0xffebebeb),
                              width: setWidth(1),
                            ),
                            borderRadius: BorderRadius.circular(setWidth(10)),
                          ),
                          padding: EdgeInsets.only(
                            left: setWidth(44),
                            right: setWidth(28),
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                '${map['cont_empe']}  ${map['contact_no']}',
                                style: TextStyle(
                                  color: chooseIndex == index ? Color(0xffea5504) : Color(0xff3f3f3f),
                                  fontSize: 15,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                              SizedBox(height: setWidth(14)),
                              Text(
                                // '江苏省 苏州市 昆山市 花桥镇 绿地大道211号 启航城晶彩小区 36号402室',
                                '${map['prv_name']} ${map['city_name']} ${map['city_area_name']} ${map['adr']}',
                                style: TextStyle(
                                  color: chooseIndex == index ? Color(0xffea5504) : Color(0xff7d7d7d),
                                  fontSize: 13,
                                ),
                              ),
                            ],
                          ),
                        ),
                      );
                    },
                    separatorBuilder: (BuildContext context, int index) {
                      return SizedBox(
                        height: setWidth(20),
                      );
                    },
                    itemCount: addressList.length + 1,
                  ),
                ),
              ),
              InkWell(
                onTap: () {
                  print('确定事件=======');
                  logic.ticketReceiptInformation(chooseIndex);
                  Get.back();
                },
                child: Container(
                  height: setWidth(96),
                  color: Color(0xffea5504),
                  alignment: Alignment.center,
                  child: Text(
                    '确定',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 17,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
// 选择发票抬头
class SelectInvoiceHeaderWidget extends StatefulWidget {
  final int chooseIndex;
  final int indexType;  // 1. 个人    2. 企业
  SelectInvoiceHeaderWidget({this.chooseIndex, this.indexType});
  @override
  State<StatefulWidget> createState() {
    return _SelectInvoiceHeaderWidget(chooseIndex: chooseIndex, indexType: indexType);
  }
}
class _SelectInvoiceHeaderWidget extends State<SelectInvoiceHeaderWidget> {
  final IssueInvoiceLogic logic = Get.put(IssueInvoiceLogic());
  int chooseIndex;
  int indexType;
  _SelectInvoiceHeaderWidget({this.chooseIndex, this.indexType});
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height / 2,
          color: Colors.white,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: EdgeInsets.only(
                  left: setWidth(20),
                  top: setWidth(12),
                  right: setWidth(20),
                  bottom: setWidth(10),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Column(
                      children: [
                        SizedBox(height: setWidth(6)),
                        Text(
                          '选择发票抬头',
                          style: TextStyle(
                            color: Color(0xff020202),
                            fontSize: 17,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ],
                    ),
                    InkWell(
                      onTap: () {
                        print('++++++++++++++ 选择发票抬头 隐藏点击事件 ++++++++++++++');
                        Get.back();
                      },
                      child: Padding(
                        padding: EdgeInsets.all(setWidth(10)),
                        child: Image.asset(
                          'assets/images/close2.png',
                          width: setWidth(50),
                          height: setWidth(50),
                          fit: BoxFit.cover,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Container(
                  child: ListView.separated(
                    scrollDirection: Axis.vertical,
                    padding: EdgeInsets.only(
                      left: setWidth(20),
                      right: setWidth(20),
                      bottom: setWidth(20),
                    ),
                    itemBuilder: (context, index) {
                      return InkWell(
                        onTap: () {
                          if (chooseIndex != index) {
                            print('++++++++++ 收票信息 选择事件 ++++++++++');
                            setState(() {
                              chooseIndex = index;
                            });
                          }
                        },
                        child: Container(
                          height: setWidth(176),
                          decoration: BoxDecoration(
                            color: Colors.white,
                            border: Border.all(
                              color: chooseIndex == index ? Color(0xffea5504) : Color(0xffebebeb),
                              width: setWidth(2),
                            ),
                            borderRadius: BorderRadius.circular(setWidth(10)),
                          ),
                          padding: EdgeInsets.only(
                            left: setWidth(44),
                            right: setWidth(28),
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                '广州腾讯科技有限公司',
                                style: TextStyle(
                                  color: chooseIndex == index ? Color(0xffea5504) : Color(0xff3f3f3f),
                                  fontSize: 17,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                              SizedBox(height: setWidth(14)),
                              Text(
                                '单位',
                                style: TextStyle(
                                  color: chooseIndex == index ? Color(0xffea5504) : Color(0xff7d7d7d),
                                  fontSize: 14,
                                ),
                              ),
                            ],
                          ),
                        ),
                      );
                    },
                    separatorBuilder: (BuildContext context, int index) {
                      return SizedBox(
                        height: setWidth(20),
                      );
                    },
                    itemCount: 3,
                  ),
                ),
              ),
              InkWell(
                onTap: () {
                  print('确定事件=======');
                  logic.invoiceHeaderClick(chooseIndex, indexType);
                  Get.back();
                },
                child: Container(
                  height: setWidth(96),
                  color: Color(0xffea5504),
                  alignment: Alignment.center,
                  child: Text(
                    '确定',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 17,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}